//
//  SGUserInfo.m
//  SGShow
//
//  Created by fanshijian on 15-3-19.
//  Copyright (c) 2015年 fanshijian. All rights reserved.
//

#import "SGUserInfo.h"

@implementation SGUserInfo

#pragma mark - 用户
// 保存登录的用户信息
+ (void)saveUserInfo:(id)model {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:model];
    [defaults setObject:myEncodedObject forKey:SG_User_Model];
}

+ (void)saveLoginPhone:(NSString *)phone password:(NSString *)password {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (phone) [defaults setObject:phone forKey:SG_Login_Phone];
    if (password) [defaults setObject:password forKey:SG_Login_Password];
}

+ (void)saveUserTypeInfo:(id)model {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:model];
    [defaults setObject:myEncodedObject forKey:SG_User_Type_Model];
}

// 获取用户信息
+ (id)getUserInfo {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *myEncodedObject = [defaults objectForKey:SG_User_Model];
    SGUserModel *aModel = [NSKeyedUnarchiver unarchiveObjectWithData:myEncodedObject];
    return aModel;
}

+ (id)getUserTypeInfo {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *myEncodedObject = [defaults objectForKey:SG_User_Type_Model];
    NSArray *aModelArray = [NSKeyedUnarchiver unarchiveObjectWithData:myEncodedObject];
    return aModelArray;
}

+ (NSString *)getLoginPhone {
    return [[NSUserDefaults standardUserDefaults] objectForKey:SG_Login_Phone];
}

+ (NSString *)getLoginPassword {
    return [[NSUserDefaults standardUserDefaults] objectForKey:SG_Login_Password];
}

#pragma mark - 存取token
+ (void)saveDeviceToken:(NSString *)token {
    if (token) {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:token forKey:@"token"];
    }
}

+ (NSString *)getDeviceToken {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"token"];
}



// 是否已登录
+ (BOOL)isLogin {
    SGUserModel *aModel = [self getUserInfo];
    if (aModel.Token) {
        return YES;
    }
    return NO;
}


@end












